<template>
  <header class="header">
    <div class="logo-section">
      <img src="@/assets/imgs/logo.png" alt="网盘logo" class="logo">
      <h1 class="app-name">我的网盘</h1>
    </div>
    <div class="user-section">
      <span class="username">{{ user?.username }}</span>
      <span v-if="user?.roleId == 1" class="member-center">会员中心</span>
      <el-button type="text" @click="logout" class="logout-button">退出</el-button>
    </div>
  </header>
</template>

<script>
import {ElMessage} from "element-plus";
import router from "@/router";

export default {
  props: {
    user: {
      type: Object,
      required: true,
      default: () => ({
        userName: '未登录用户',
        roleId: 0
      })
    }
  },
  methods: {
    logout() {
      ElMessage.success('退出成功');
      //localStorage.removeItem('userName');
      localStorage.removeItem('userInfo');
      //localStorage.removeItem('token');
      router.push('/login');
    }
  }
}
</script>
<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background-color: #e6eef8;
  color: black;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logo-section {
  display: flex;
  align-items: center;
}

.logo {
  width: 40px;
  height: 40px;
  margin-right: 10px;
  border-radius: 50%;
  object-fit: cover;
}

.app-name {
  margin: 0;
  font-size: 1.5em;
  font-weight: bold;
  color: #2c3e50;
}

.user-section {
  display: flex;
  align-items: center;
  gap: 15px;
}
.username {
  font-weight: bold;
  margin-right: 10px;
  color: #2c3e50;
}
.member-center {
  font-weight: bold;
  color: #3498db;
  cursor: pointer;
  transition: color 0.2s;
}
.member-center:hover {
  color: #2980b9;
  text-decoration: underline;
}
.logout-button {
  padding: 8px 16px;
  background-color: #e74c3c;
  color: white;
  border-radius: 4px;
  transition: all 0.2s;
  border: none;
}

.logout-button:hover {
  background-color: #c0392b;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.logout-button:active {
  transform: translateY(0);
}
</style>